package com.qianxun.module.application.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianxun.module.application.common.CommonUtil;
import com.qianxun.module.application.entity.DataSortQueryTable;
import com.qianxun.module.application.mapper.DataSortQueryTableMapper;
import com.qianxun.module.application.service.DataSortQueryTableService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 数据排序处理类
 *
 * @author Admin
 */
@Service
public class DataSortQueryTableServiceImpl extends ServiceImpl<DataSortQueryTableMapper, DataSortQueryTable> implements DataSortQueryTableService {

    @Override
    public DataSortQueryTable queryByAppIdAndDataType(String appId, String dataType) {
        LambdaQueryWrapper<DataSortQueryTable> wrapper = new QueryWrapper<DataSortQueryTable>().lambda();
        wrapper.eq(DataSortQueryTable::getAppId, appId);
        wrapper.eq(DataSortQueryTable::getDataType, dataType);
        return this.getOne(wrapper);
    }

    @Override
    public List<String> querySortList(String appId, String dataType) {
        DataSortQueryTable dataSortQueryTable = queryByAppIdAndDataType(appId, dataType);
        if (Objects.nonNull(dataSortQueryTable)) {
            return CommonUtil.dealSortList(dataSortQueryTable, false);
        }
        return null;
    }

}
